import static java.lang.Math.round;

public class SavingsAccount extends BankAccount2{
    //每月都有利息产生
    //每月存款次数+取款次数共计3次内面授手续费
    private int count=3;
//    利率
    private double rate=0.01;
    public SavingsAccount(double balance){
        super(balance);
    }
    @Override
    public void deposit(double amount){
        if(count>0){
            super.deposit(amount);
        }else{
            super.deposit(amount-1);

        }
        count--;

    }
    @Override
    public void withdraw(double amount){
        if(count>0){
            super.withdraw(amount);
        }else{
            super.withdraw(amount+1);

        }
        count--;
    }
    public void earnMonthlyInterest(){
        //每个月初，我们统计上个月的利息，同时将count重置=3
        count=3;
        super.deposit(round(getBalance()*rate/12));
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }
}
